import Commonmsg from '../../../public/js/commonmsg'
const state = {
  closed: false,
  msgTargetValue: null,
  msgFlowState: null,
  msgFlowStart: null,
  msgFlowStop: null,
  msgFlowNodeOk: null,
  msgFlowNodeErr: null,
  msgParamSet: null,
  msgAgentDisconnect: null,
  msgFlowVclrst: null
}

const mutations = {
  CHANGE_WM_TARGET_VALUE: (state, vPar) => {
    state.msgTargetValue = vPar
  },
  CHANGE_WM_FLOW_STATE: (state, vPar) => {
    state.msgFlowState = vPar
  },
  CHANGE_WM_FLOW_START: (state, vPar) => {
    state.msgFlowStart = vPar
  },
  CHANGE_WM_FLOW_STOP: (state, vPar) => {
    state.msgFlowStop = vPar
  },
  CHANGE_WM_FLOW_NODE_OK: (state, vPar) => {
    state.msgFlowNodeOk = vPar
  },
  CHANGE_WM_FLOW_NODE_ERR: (state, vPar) => {
    state.msgFlowNodeErr = vPar
  },
  CHANGE_WM_PARAM_SET: (state, vPar) => {
    state.msgParamSet = vPar
  },
  CHANGE_WM_AGENT_DISCONNECT: (state, vPar) => {
    state.msgAgentDisconnect = vPar
  },
  CHANGE_WM_FLOW_VCLRST: (state, vPar) => {
    state.msgFlowVclrst = vPar
  },
  CHANGE_SCREENMSG: (state, flag) => {
    state.closed = flag
  }
}
const actions = {
  getMsgData({ commit, state }) {
    var timer = null
    function CBigScreenMgrMessages() {
      this.isClosed = function() {
        return state.closed
      }
      this.WndProc = function(msg, vPar) {
        switch (msg) {
          case Commonmsg.WM_TARGET_VALUE: {
            if (timer === null) {
              timer = setTimeout(() => {
                commit('CHANGE_WM_TARGET_VALUE', vPar)
                timer = null
              }, 200)
            } else {
              commit('CHANGE_WM_TARGET_VALUE', vPar)
            }

            break
          }
          case Commonmsg.WM_FLOW_STATE: {
            commit('CHANGE_WM_FLOW_STATE', vPar)
            break
          }
          case Commonmsg.WM_FLOW_START: {
            commit('CHANGE_WM_FLOW_START', vPar)
            break
          }
          case Commonmsg.WM_FLOW_STOP: {
            commit('CHANGE_WM_FLOW_STOP', vPar)
            break
          }
          case Commonmsg.WM_FLOW_NODE_OK: {
            commit('CHANGE_WM_FLOW_NODE_OK', vPar)
            break
          } case Commonmsg.WM_FLOW_NODE_ERR: {
            commit('CHANGE_WM_FLOW_NODE_ERR', vPar)
            break
          }
          case Commonmsg.WM_PARAM_SET: {
            commit('CHANGE_WM_PARAM_SET', vPar)
            break
          }
          case Commonmsg.WM_AGENT_DISCONNECT: {
            commit('CHANGE_WM_AGENT_DISCONNECT', vPar)
            break
          }
          case Commonmsg.WM_FLOW_VCLRST: {
            commit('CHANGE_WM_FLOW_VCLRST', vPar)
            break
          }
        }
      }
    }
    top.mainMessages.regMessages(new CBigScreenMgrMessages(), [Commonmsg.WM_TARGET_VALUE, Commonmsg.WM_FLOW_STATE, Commonmsg.WM_FLOW_START, Commonmsg.WM_FLOW_STOP, Commonmsg.WM_FLOW_NODE_OK, Commonmsg.WM_FLOW_NODE_ERR, Commonmsg.WM_PARAM_SET, Commonmsg.WM_AGENT_DISCONNECT, Commonmsg.WM_FLOW_VCLRST])
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
